from django.contrib.auth.models import AbstractUser
from django.db import models


# Create your models here.
class UserModel(AbstractUser):
    phone = models.CharField(max_length=15, blank=True, null=True, verbose_name='手机号')
    nickname = models.CharField(max_length=50, blank=True, null=True, verbose_name='昵称')
    avatar = models.ImageField(upload_to='avatar/%Y/%m/%d', blank=True, null=True, verbose_name='头像')
    gender = models.CharField(max_length=10, blank=True, null=True, verbose_name='性别')
    age = models.IntegerField(blank=True, null=True, verbose_name='年龄')
    birthday = models.DateField(blank=True, null=True, verbose_name='生日')
    address = models.CharField(max_length=100, blank=True, null=True, verbose_name='地址')

    class Meta:
        verbose_name = '用户'
        verbose_name_plural = verbose_name
        db_table = 'user_model'

    def __str__(self):
        return self.username


class GoodsModel(models.Model):
    name = models.CharField(max_length=50, verbose_name='商品名称')
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='商品价格', default=0.00)
    stock = models.IntegerField(verbose_name='商品库存', default=0, help_text='库存为0表示已售空', null=True,
                                blank=True)
    description = models.TextField(verbose_name='商品描述', blank=True, null=True)
    image = models.ImageField(upload_to='goods/%Y/%m/%d', verbose_name='商品图片', blank=True, null=True)

    class Meta:
        verbose_name = '商品'
        verbose_name_plural = verbose_name
        db_table = 'goods_model'

    def __str__(self):
        return self.name


class BannerModel(models.Model):
    image = models.ImageField(upload_to='banner/%Y/%m', verbose_name='轮播图图片', blank=True, null=True)
    url = models.CharField(max_length=200, verbose_name='跳转链接', blank=True, null=True)

    class Meta:
        verbose_name = '轮播图'
        verbose_name_plural = verbose_name
        db_table = 'banner_model'


class ShopModel(models.Model):
    name = models.CharField(max_length=50, verbose_name='商品名称')
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='商品价格', default=0.00)
    stock = models.IntegerField(verbose_name='商品库存', default=0, help_text='库存为0表示已售空', null=True,
                                blank=True)
    description = models.TextField(verbose_name='商品描述', blank=True, null=True)
    image = models.ImageField(upload_to='goods/%Y/%m/%d', verbose_name='商品图片', blank=True, null=True)

    class Meta:
        verbose_name = '商品'
        verbose_name_plural = verbose_name
        db_table = 'shop_model'

    def __str__(self):
        return self.name
